// packageG/mycomponent/teamName/teamName.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    member: {
      type: Boolean,
      value: false
    },
    info_basic_member_team:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    nameVal: "",
    // 标题
  },
  observers:{
    'show':function(showb){}
  },
  
  lifetimes: {
    attached: function () {
      // try {
      //   setTimeout(() => {
      //     let yz_basic_info = wx.getStorageSync('yz_basic_info');
      //     this.setData({
      //       info_basic_member_team: yz_basic_info.globalParameter && yz_basic_info.globalParameter.member_team ? yz_basic_info.globalParameter.member_team : false
      //     })
      //   }, 500);
        
      // } catch (error) {
        
      // }
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    tapinp(e){
      this.setData({
        nameVal:e.detail
      })
    },
    cancelTap() {
      this.triggerEvent('childShow',false)
    },
    confirmTap() {
      console.log('dddddddd',app._isTextEmpty(this.data.nameVal))
      if (!app._isTextEmpty(this.data.nameVal)) {
        // 不为空就请求接口
        let url = ''
        if (this.data.member) {
          // 会员中心是编辑
          url = app.getNetAddresss('plugin.member-team.frontend.controllers.team.edit');
        } else {
          // 首页的是新增
          url = app.getNetAddresss('plugin.member-team.frontend.controllers.team.add');
        }
        let json = {
          team_name: this.data.nameVal,
          basic_info: 1
        }
        app._getNetWork({
          url: url,
          data: json,
          success: (resdata) => {
            var res = resdata.data;
            if (res.result == 1) {
              this.triggerEvent('childShow',false)
              console.log(res.data.name,'wwwwwwwwddd')
              this.triggerEvent('editTeamName',res.data.name)
              wx.showToast({
                title: res.msg,
                duration: 1000,
                icon: 'none'
              })
            } else {
              this.triggerEvent('childShow',false)
              wx.showToast({
                title: res.msg,
                duration: 1000,
                icon: 'none'
              })
            }
          },
        });

      }
    }
  }
})